#include "Stack.h"


Stack::Stack(int n)
{
	this->size = n;
	this->pitems = new Item[this->size];
	this->top = 0;
}
Stack::Stack(const Stack& st)
{
	this->size = st.size;
	this->top = st.top;
	this->pitems = new Item[this->size];
	for (int i = 0; i < this->size; i++)
	{
		this->pitems[i] = st.pitems[i];
	}
}
Stack::~Stack()
{
	if (this->pitems)
	{
		delete[] this->pitems;
		this->pitems = NULL;
	}
}

bool Stack::isempty()const
{
	return this->top == 0;
}
bool Stack::isfull()const
{
	return this->top == MAX;
}
bool Stack::push(const Item& item)
{
	if (isfull())return false;
	this->pitems[this->top++] = item;
	return true;
}
bool Stack::pop(Item& item)
{
	if (isempty())return false;
	item = this->pitems[--this->top];
	return true;
}

Stack& Stack::operator=(const Stack& st)
{
	if (this == &st)return*this;
	delete[] this->pitems;
	this->size = st.size;
	this->top = st.top;
	this->pitems = new Item[this->size];
	for (int i = 0; i < this->size; i++)
	{
		this->pitems[i] = st.pitems[i];
	}
	return *this;
}

ostream& operator<<(ostream& os, const Stack& s)
{
	for (int i = 0; i < s.top; i++)
	{
		os << s.pitems[i] << " ";
	}
	return os;
}
